using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ASPNETVN.PORTAL.Components.UI;
using ASPNETVN.PORTAL.Modules.MENU.Components;

namespace ASPNETVN.PORTAL.Modules.MENU.Controls
{
    public partial class ItemManager : AddEditItemControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void gvMenus_SelectedIndexChanged(object sender, EventArgs e)
        {
            tblAddSubMenu.Visible = gvMenus.SelectedIndex >= 0;
        }

        protected void btnAddMenu_Click(object sender, EventArgs e)
        {
            Item menu = new Item();
            menu.ParentID = 0;
            menu.ModuleID = this.ModuleID;
            menu.Title = txtTitle.Text;
            menu.Url = txtUrl.Text;
            menu.SortOrder = Convert.ToInt32(txtOrder.Text);
            menu.Target = ddlTarget.SelectedValue;

            menu.Insert();

            gvMenus.DataBind();
            resetMenu();
        }

        protected void resetMenu()
        {
            txtTitle.Text = "";
            txtUrl.Text = "";
            txtOrder.Text = "";
            ddlTarget.SelectedIndex = 0;
        }

        protected void resetSubMenu()
        {
            txtSubTitle.Text = "";
            txtSubLink.Text = "";
            txtSubOrder.Text = "";
            ddlSubTarget.SelectedIndex = 0;
        }

        protected void btnAddSubMenu_Click(object sender, EventArgs e)
        {
            Item submenu = new Item();
            submenu.ParentID = Convert.ToInt32(gvMenus.SelectedValue);
            submenu.ModuleID = this.ModuleID;
            submenu.Title = txtSubTitle.Text;
            submenu.Url = txtSubLink.Text;
            submenu.SortOrder = Convert.ToInt32(txtSubOrder.Text);
            submenu.Target = ddlSubTarget.SelectedValue;

            submenu.Insert();

            gvSubMenus.DataBind();
            resetSubMenu();
        }
    }
}